#include <iomanip>
#include <iostream>
#include <string.h>
using namespace std;

#define MAXSIZE 100

//书
struct Book {
    char no[50];
    char name[50];
    float price;
};

//节点
typedef struct Node {
    Book *book;
    int length;
} SeqList;

//初始化
void initList(SeqList *L) {
    L->book = (Book *) malloc(MAXSIZE * sizeof(Book));
    L->length = 0;
}

//输入方式1
void firstInput(SeqList *L) {
    for (int i = 0; i < MAXSIZE; i++) {
        cin >> L->book[i].no >> L->book[i].name >> L->book[i].price;
        if (strcmp(L->book[i].no, "0") == 0 && strcmp(L->book[i].name, "0") == 0 && L->book[i].price == 0) {
            break;
        }
        L->length++;
    }
}

// 输入方式2
void secondInput(SeqList *L) {
    int num = 0;
    cin >> num;
    for (int i = 0; i < num; i++) {
        cin >> L->book[i].no >> L->book[i].name >> L->book[i].price;
        L->length++;
    }
}

//输出
void displayList(SeqList *L) {
    for (int i = 0; i < L->length; i++) {
        cout << L->book[i].no << " " << L->book[i].name << " " << fixed << setprecision(2) << L->book[i].price << endl;
    }
}

//输出
void outPrint(SeqList *L) {
    cout << L->length << endl;
    for (int i = 0; i < L->length; i++) {
        cout << L->book[i].no << " " << L->book[i].name << " " << fixed << setprecision(2) << L->book[i].price << endl;
    }
}

//排序
void listSort(SeqList *L) {
    for (int i = 0; i < L->length; i++) {
        for (int j = 0; j < L->length - 1; j++) {
            if (L->book[j].price < L->book[j + 1].price) {
                Book temp = L->book[j];
                L->book[j] = L->book[j + 1];
                L->book[j + 1] = temp;
            }
        }
    }
    displayList(L);
}

//平均价格
void average(SeqList *L) {
    //平均值
    float avg = 0.0;

    for (int i = 0; i < L->length; i++) {
        avg += L->book[i].price;
    }
    avg /= L->length;
    cout << fixed << setprecision(2) << avg << endl;
    //修改价格高于等于平均数增加0.1，低于增加0.2
    for (int i = 0; i < L->length; i++) {
        if (L->book[i].price < avg) {
            L->book[i].price = L->book[i].price * (1 + 0.2);
        } else {
            L->book[i].price = L->book[i].price * (1 + 0.1);
        }
    }
    displayList(L);
}

//逆序
void reverse(SeqList *L) {
    for (int i = 0; i < L->length; i++) {
        for (int j = 0; j < L->length - i - 1; j++) {
            Book temp = L->book[j];
            L->book[j] = L->book[j + 1];
            L->book[j + 1] = temp;
        }
    }
    displayList(L);
}

//最贵书本
void maxPrice(SeqList *L) {
    //最大值
    float max = 0.0;
    Book temp[MAXSIZE];
    int max_count = 0;
    for (int i = 0; i < L->length; i++) {
        if (L->book[i].price > max) {
            max = L->book[i].price;
            temp[max_count] = L->book[i];
        } else if (L->book[i].price == max) {
            max_count++;
            temp[max_count] = L->book[i];
        }
    }
    cout << max_count + 1 << endl;
    for (int i = 0; i <= max_count; i++) {
        cout << temp[i].no << " " << temp[i].name << " " << fixed << setprecision(2) << temp[i].price << endl;
    }
}

//最喜爱的书
void favorite(SeqList *L) {
    int num = 0;
    int c_num = 0;
    bool flag = false;
    Book temp[MAXSIZE];
    Book favorite[MAXSIZE];
    cin >> num;
    for (int i = 0; i < num; i++) {
        cin >> temp[i].name;
    }
    //比对
    for (int i = 0; i < num; i++) {
        for (int j = 0; j < L->length; j++) {
            if (strcmp(temp[i].name, L->book[j].name) == 0) {
                favorite[c_num++] = L->book[j];
                flag = true;
            }
        }
        if (flag == false) {
            cout << "Sorry,there is no your favourite!" << endl;
        }
    }

    //输出
    cout << c_num << endl;
    for (int i = 0; i < c_num; i++) {
        cout << favorite[i].no << " " << favorite[i].name << " " << fixed << setprecision(2) << favorite[
            i].price << endl;
    }
}

//最佳位置
void location(SeqList *L) {
    int num = 0; //查找次数
    cin >> num;
    int c_num[MAXSIZE]; //位置表
    for (int i = 0; i < num; i++) {
        cin >> c_num[i];
    }

    for (int j = 0; j < num; j++) {
        int flag = 0;
        for (int i = 0; i < L->length - 1; i++) {
            if (c_num[j] == i + 1) //位置
            {
                cout << L->book[i].no << " " << L->book[i].name << " " << fixed << setprecision(2) << L->book[i].price
                        << endl;
                flag = 1;
            }
        }
        if (flag == 0)
            cout << "Sorry，the book on the best position doesn't exist!" << endl;
    }
}

//入库
void addBook(SeqList *L) {
    return;
}

//出库
void removeBook(SeqList *L) {
}

//去重
void deduplication(SeqList *L) {
}


//主函数
int main() {
    SeqList L;
    //init
    initList(&L);
    //0 0 0截止
    firstInput(&L);
    //个数指定
    // secondInput(&L);
    //输出
     outPrint(&L);
    //排序
    // listSort(&L);
    //平均修改
    // average(&L);
    //逆序
    // reverse(&L);
    //最贵
    // maxPrice(&L);
    //最爱
    // favorite(&L);
    //位置
    // location(&L);
    //入库
    //addBook(&L);
    //出库
    // removeBook(&L);
    //去重
    // deduplication(&L);
    return 0;
}
